package com.fenghongzhang.day009;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class MySqlHelp extends SQLiteOpenHelper {

    private static final String TAG = "MySqlHelp";
    /**
     *
     * @param context 上下文
     * @param name  数据库的名字
     * @param factory  null
     * @param version 1 -> 大
     */
    public MySqlHelp(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    //创建

    /**
     * 只会一直一次.
     *
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "onCreate: ");
        //创建表
//        db.execSQL("create table ha");

        db.beginTransaction();
        //插入10条测试数据.
        for (int i = 0; i < 1000; i++) {
//            db.execSQL("insert into ");
        }
        db.setTransactionSuccessful();
        db.endTransaction();

    }

    //更新
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "onUpgrade: ");
//        db.execSQL("create table 2");
        db.beginTransaction();
        //插入10条测试数据.
        for (int i = 0; i < 1000; i++) {
//            db.execSQL("insert into ");
        }
        db.setTransactionSuccessful();
        db.endTransaction();

    }
}
